home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 7 / Apprentice-Release7.iso / Source Code / Pascal / Applications / P4⁄Mac 2.0d4 / Original source & doc / READ.ME < prev   
Encoding:
Text File  |  1994-07-28  |  8.2 KB  |  256 lines  |  [TEXT/ttxt]

  1. This is the Pascal source of a public domain Pascal compiler and
  2. interpreter, the P4 compiler and interpreter. It is coded entirely in
  3. Pascal, and produces a high-level so-called intermediate code as
  4. output. The program 'pint' is an assembler and interpreter for this
  5. language.
  6.  
  7. The entire compiler and interpreter is documented in the book:
  8.     Pascal Implementation
  9.     by Steven Pemberton and Martin Daniels
  10.     published by Ellis Horwood, Chichester, UK.
  11.     ISBN: 0-13-653-0311
  12. (also available in Japanese).
  13. It was distributed by John Wiley in other countries, but now that
  14. Prentice Hall has taken over Ellis Horwood, that will have changed.
  15.  
  16. Steven Pemberton is contactable by email as Steven.Pemberton@cwi.nl.
  17.  
  18. What you have to do to use this compiler:
  19.  
  20.     Compile pcom.p and pint.p with a Pascal compiler. You
  21.     obviously have to have a Pascal compiler already. This gives
  22.     you a Pascal compiler (pcom) that produces P4 code,
  23.     and an interpreter (pint) that runs P4 code.
  24.  
  25.     To use the compiler, run pcom with the Pascal program as
  26.     standard input. This produces any diagnostics on standard
  27.     output, and its code on a Pascal file that is called prr.
  28.     Check with your Pascal compiler how this gets assigned to a
  29.     file in the filestore. You may have to change the lines
  30.     'rewrite(prr)' in pcom.p and pint.p and 'reset(prd)' in pint.p
  31.     for your compiler, for instance to "rewrite(prr, 'prr')" etc.
  32.  
  33.     To run the resulting code, run pint with the prr output
  34.     produced by pcom as input for the file 'prd', and input for
  35.     the compiled pascal program on standard input.
  36.  
  37.     For instance, do this once:
  38.         pc -o pcom pcom.p
  39.         pc -o pint pint.c
  40.     and for each program:
  41.         pcom < test.p  # produces file prr containing the p4 code
  42.         mv prr prd
  43.         pint < input
  44.  
  45.     You have to supply input to pint, even if the program doesn't
  46.     read from it, for instance:
  47.         pint < /dev/null
  48.  
  49. If you intend to compile pcom with itself, there are two lines that
  50. have to be commented out when you do; search for the word 'comment' in
  51. the pcom source. There is no reason why you should want to compile
  52. pint.p with pcom.
  53.  
  54. DIFFERENCES WITH THE BOOK
  55.  
  56. The code here is slightly different from that in the book, but the
  57. line numbers have been kept the same.  The changes were to allow
  58. modern Pascal compilers to compile the source (there were some
  59. laxities in the original code). The following are the changes:
  60.  
  61. The type marktype is added for the parameters of the routines mark and
  62. release:
  63.     76c76
  64.     < 
  65.     ---
  66.     >      marktype= ^integer;
  67.  
  68. The type setty (which represents set types) is added for the new type
  69. compatibility rules of ISO Pascal:
  70.     95c95
  71.     < 
  72.     ---
  73.     >      setty = set of setlow..sethigh;
  74.     100c100
  75.     <                          pset: (pval: set of setlow..sethigh);
  76.     ---
  77.     >                          pset: (pval: setty);
  78.  
  79. Missing variant parts:
  80.     123c123
  81.     <                                   declared: (fconst: ctp));
  82.     ---
  83.     >                                   declared: (fconst: ctp); standard: ());
  84.     145a146
  85.     >                      types: ();
  86.     149,150c150
  87.     <                      proc,
  88.     <                      func:  (case pfdeckind: declkind of
  89.     ---
  90.     >                      proc, func:  (case pfdeckind: declkind of
  91.     154,155c154,155
  92.     <                                            actual: (forwdecl, extern:
  93.     <                                                     boolean)))
  94.     ---
  95.     >                                            actual: (forwdecl, extern: boolean);
  96.     >                                            formal: ()))
  97.  
  98. Pcom has the files prr and prd as standard identifiers. You have to
  99. declare them for other compilers:
  100.     193d192
  101.     < 
  102.     194a194
  103.     >     prr: text; (* comment this out when compiling with pcom *)
  104.     299d298
  105.     < 
  106.  
  107. Other compilers don't have the routines mark and release. Their
  108. effective semantics are null; you just waste heap:
  109.     300a300,301
  110.     >   procedure mark(var p: marktype); begin end;
  111.     >   procedure release(p: marktype); begin end;
  112.     302d302
  113.     < 
  114.  
  115. Output the line number with error messages, so that if the listing
  116. option has been switched off, you still know which line is in error:
  117.     307c307
  118.     <       begin write(output,' ****  ':15);
  119.     ---
  120.     >       begin write(output,linecount:6,' ****  ':9);
  121.  
  122. Accept tabs as white-space as well:
  123.     398c398
  124.     <     repeat while (ch = ' ') and not eol do nextch;
  125.     ---
  126.     >     repeat while ((ch = ' ') or (ch = '    ')) and not eol do nextch;
  127.  
  128. Jumping from the then part of an if into the else part is not allowed;
  129. fix cases like 1..10 in another way:
  130.     429c429
  131.     <           if (ch = '.') or (ch = 'e') then
  132.     ---
  133.     >           if ((ch = '.') and (input^ <> '.')) or (ch = 'e') then
  134.     434c434
  135.     <                       nextch; if ch = '.' then begin ch := ':'; goto 3 end;
  136.     ---
  137.     >                       nextch; (*if ch = '.' then begin ch := ':'; goto 3 end;*)
  138.  
  139. Fix modern type mismatches:
  140.     668c668
  141.     <   procedure align(fsp: stp; var flc: integer);
  142.     ---
  143.     >   procedure align(fsp: stp; var flc: addrrange);
  144.  
  145. An identifier misspelled after the 8th character:
  146.     872c872
  147.     <           if sy = stringconstsy then
  148.     ---
  149.     >           if sy = stringconst then
  150.  
  151. Unused variables, and new type names:
  152.     1529,1531c1529,1531
  153.     <       var oldlev: 0..maxlevel; lsy: symbol; lcp,lcp1: ctp; lsp: stp;
  154.     <           forw: boolean; oldtop: disprange; parcnt: integer;
  155.     <           llc,lcm: addrrange; lbname: integer; markp: ^integer;
  156.     ---
  157.     >       var oldlev: 0..maxlevel; lcp,lcp1: ctp; lsp: stp;
  158.     >           forw: boolean; oldtop: disprange;
  159.     >           llc,lcm: addrrange; lbname: integer; markp: marktype;
  160.     1535c1535
  161.     <           llc: addrrange; count,lsize: integer;
  162.     ---
  163.     >           llc,lsize: addrrange; count: integer;
  164.     1819c1819
  165.     <           i, entname, segsize: integer;
  166.     ---
  167.     >           entname, segsize: integer;
  168.     2087c2087
  169.     <         var lattr: attr; lcp: ctp; lsize,lmin,lmax: integer;
  170.     ---
  171.     >         var lattr: attr; lcp: ctp; lsize: addrrange; lmin,lmax: integer;
  172.     2248c2248
  173.     <             var lcp:ctp; llev:levrange; laddr:addrrange;
  174.     ---
  175.     >             var llev:levrange; laddr:addrrange;
  176.     2306c2306
  177.     <                 lcp:ctp; llev:levrange; laddr,len:addrrange;
  178.     ---
  179.     >                 llev:levrange; laddr,len:addrrange;
  180.     2456,2457c2456,2457
  181.     <             var lsp,lsp1: stp; varts,lmin,lmax: integer;
  182.     <                 lsize,lsz: addrrange; lval: valu;
  183.     ---
  184.     >             var lsp,lsp1: stp; varts: integer;
  185.     >                 lsize: addrrange; lval: valu;
  186.     2750c2750
  187.     <                     cstpart: set of 0..47; lsp: stp;
  188.     ---
  189.     >                     cstpart: setty; lsp: stp;
  190.  
  191. Unix pc can't cope with this line:
  192.     2926c2926
  193.     <             (*/*)     rdiv: begin
  194.     ---
  195.     >             (* / *)   rdiv: begin
  196.  
  197. More unused variables:
  198.     3318c3318
  199.     <           var lattr: attr; lsp: stp;  lsy: symbol;
  200.     ---
  201.     >           var lattr: attr;  lsy: symbol;
  202.     3642c3642
  203.     <     var sp: stp;
  204.     ---
  205.     > 
  206.  
  207. Produce code as default:
  208.     3800c3800
  209.     <     prtables := false; list := true; prcode := false; debug := true;
  210.     ---
  211.     >     prtables := false; list := true; prcode := true; debug := true;
  212.  
  213. Unused variable:
  214.     3868c3868
  215.     <       var i: integer; ch: char;
  216.     ---
  217.     >       var i: integer;
  218.  
  219. Other compilers need to rewrite prr before using it:
  220.     3995,3996c3995,3996
  221.     <   (*compile:*)
  222.     <   (**********)
  223.     ---
  224.     >   (*compile:*) rewrite(prr); (*comment this out when compiling with pcom *)
  225.     >   (**********)
  226.  
  227. And all variables called 'extern' have been renamed to 'externl'.
  228.  
  229. Differences in the interpreter are minimal:
  230.  
  231. a set type has been added:
  232.     45a46
  233.     >       settype     = set of 0..58;
  234.     63c64
  235.     <                                 sett       :(vs :set of 0..47);
  236.     ---
  237.     >                                 sett       :(vs :settype);
  238.     225c226
  239.     <       var name :alfa;  b :boolean;  r :real;  s :set of 0..58;
  240.     ---
  241.     >       var name :alfa;  b :boolean;  r :real;  s :settype;
  242.  
  243. the initial writeln has been removed:
  244.     667c667
  245.     <   writeln(output); (* for testing *)
  246.     ---
  247.     >   (* writeln(output); for testing *)
  248.  
  249. and the type alfa has been added:
  250.     47c47
  251.     < 
  252.     ---
  253.     >       alfa      = packed array[1..10] of char;
  254.  
  255. End of differences
  256.